<?php
namespace App\Utils;

/**
 * 角色权限管理工具类
 * @package App\Utils
 */
class RolesUtil
{
    /**
     * 返回全部的权限配置数组
     */
    public static function allPermissions()
    {
        return array(
            [//工作台=======================================================================================
                "permission" => "purview.worker",               //权限标识，只允许出现 字符串 和 .
                "title"      => "工作台",                        //权限标题
                "des"        => "是否能够操作工作台区域？",         //权限的详细描述信息
                "super"      => false,                          //是否只有超级管理员（内置）才能看见此权限
                "parent"     => null                            //父权限
            ],
            [
                "permission" => "permission.withdraw",
                "title"      => "申请提现",
                "des"        => "是否可以浏览并操作会员提现申请？",
                "super"      => false,
                "parent"     => "purview.worker"
            ],
            [
                "permission" => "permission.debit",
                "title"      => "充值/扣款",
                "des"        => "是否可以进行会员的充值/扣款操作？",
                "super"      => false,
                "parent"     => "purview.worker"
            ],
            [
                "permission" => "permission.bonus",
                "title"      => "查看奖金明细",
                "des"        => "是否可以查看后台的所有奖金明细？",
                "super"      => false,
                "parent"     => "purview.worker"
            ],
            [
                "permission" => "permission.consume",
                "title"      => "查看消费明细",
                "des"        => "是否可以查看后台所有会员的资金变动记录？",
                "super"      => false,
                "parent"     => "purview.worker"
            ],
            [
                "permission" => "permission.transfer",
                "title"      => "查看转账明细",
                "des"        => "是否可以查看后台所有会员的转账记录？",
                "super"      => false,
                "parent"     => "purview.worker"
            ],
            [
                "permission" => "permission.remit",
                "title"      => "处理打款申请单",
                "des"        => "是否可以进行会员的打款申请单操作？",
                "super"      => false,
                "parent"     => "purview.worker"
            ],
            [
                "permission" => "permission.order",
                "title"      => "订单管理",
                "des"        => "是否可以查看并操作后台所有订单？",
                "super"      => false,
                "parent"     => "purview.worker"
            ],
            [//会员管理=====================================================================================
                "permission" => "purview.user",
                "title"      => "会员管理",
                "des"        => "是否能够操作会员管理区域？",
                "super"      => false,
                "parent"     => null],
            [
                "permission" => "permission.users",
                "title"      => "查看/搜索会员",
                "des"        => "是否可以浏览并操作会员信息？",
                "super"      => false,
                "parent"     => "purview.user"
            ],
//            [
//                "permission" => "permission.reg",
//                "title"      => "注册内部会员",
//                "des"        => "是否可以注册内部会员？",
//                "super"      => false,
//                "parent"     => "purview.user"
//            ],
//            [
//                "permission" => "permission.info",
//                "title"      => "会员信息采集",
//                "des"        => "是否可以添加会员？",
//                "super"      => false,
//                "parent"     => "purview.user"
//            ],
            [
                "permission" => "permission.actived",
                "title"      => "激活会员",
                "des"        => "是否可以激活指定会员？",
                "super"      => false,
                "parent"     => "purview.user"
            ],
            [
                "permission" => "permission.vipup",
                "title"      => "升级会员",
                "des"        => "是否可以升级指定会员？",
                "super"      => false,
                "parent"     => "purview.user"
            ],
            [
                "permission" => "permission.nodetree",
                "title"      => "节点关系图",
                "des"        => "是否可以查看会员节点关系图？",
                "super"      => false,
                "parent"     => "purview.user"
            ],
            [
                "permission" => "permission.ztree",
                "title"      => "推荐关系图",
                "des"        => "是否可以查看会员推荐关系图？",
                "super"      => false,
                "parent"     => "purview.user"
            ],
            [
                "permission" => "permission.bdzx",
                "title"      => "报单中心管理",
                "des"        => "是否可以浏览并操作报单中心？",
                "super"      => false,
                "parent"     => "purview.user"
            ],
            [//信息管理=====================================================================================
                "permission" => "purview.news",
                "title"      => "信息管理",
                "des"        => "是否能够操作信息管理区域？",
                "super"      => false,
                "parent"     => null],
            [
                "permission" => "permission.classify",
                "title"      => "操作信息分类",
                "des"        => "是否可以编辑/删除信息的分类.",
                "super"      => false,
                "parent"     => "purview.news"
            ],
            [
                "permission" => "permission.slug.classify",
                "title"      => "操作碎片分类",
                "des"        => "是否可以编辑/删除碎片的分类.",
                "super"      => false,
                "parent"     => "purview.news"
            ],
            [
                "permission" => "permission.slugs",
                "title"      => "操作碎片内容",
                "des"        => "是否可以编辑/删除碎片内容.",
                "super"      => false,
                "parent"     => "purview.news"
            ],
            [
                "permission" => "permission.news",
                "title"      => "文章编辑",
                "des"        => "是否可以编辑/删除文章.",
                "super"      => false,
                "parent"     => "purview.news"
            ],
            [
                "permission" => "permission.bulletin",
                "title"      => "系统公告",
                "des"        => "是否可以编辑/删除系统公告.",
                "super"      => false,
                "parent"     => "purview.news"
            ],
            [
                "permission" => "permission.feedback",
                "title"      => "会员咨询",
                "des"        => "是否可以查看/回复会员的问题咨询.",
                "super"      => false,
                "parent"     => "purview.news"
            ],
            [//模式管理=====================================================================================
                "permission" => "purview.rule",
                "title"      => "模式管理",
                "des"        => "是否能够操作模式管理区域？",
                "super"      => false,
                "parent"     => null],
            [
                "permission" => "permission.mode",
                "title"      => "模式参数设置",
                "des"        => "是否可以修改系统的奖金结算参数.",
                "super"      => false,
                "parent"     => "purview.rule"
            ],
            [
                "permission" => "permission.switch",
                "title"      => "系统功能开关设置",
                "des"        => "是否可以修改系统功能开关设置.",
                "super"      => false,
                "parent"     => "purview.rule"
            ],
            [
                "permission" => "permission.email",
                "title"      => "系统邮箱设置",
                "des"        => "是否可以修改系统邮箱配置.",
                "super"      => false,
                "parent"     => "purview.rule"
            ],
            [//系统设置=====================================================================================
                "permission" => "purview.setting",
                "title"      => "系统设置",
                "des"        => "是否能够操作系统设置区域？",
                "super"      => false,
                "parent"     => null],
            [
                "permission" => "permission.webinfo",
                "title"      => "站点信息设置",
                "des"        => "控制站点的名称和站点关闭/开启功能.",
                "super"      => false,
                "parent"     => "purview.setting"
            ],
            [
                "permission" => "permission.logintheme",
                "title"      => "登录界面皮肤",
                "des"        => "动态的切换登录页面主题.",
                "super"      => false,
                "parent"     => "purview.setting"
            ],
            [
                "permission" => "permission.initial",
                "title"      => "一键初始化",
                "des"        => "删除数据库数据.",
                "super"      => false,
                "parent"     => "purview.setting"
            ],
            [
                "permission" => "permission.test",
                "title"      => "一键测试",
                "des"        => "一键测试系统功能",
                "super"      => false,
                "parent"     => "purview.setting"
            ],
            [
                "permission" => "permission.admins",
                "title"      => "管理员管理",
                "des"        => "添加/删除/查看后台系统的管理员.",
                "super"      => false,
                "parent"     => "purview.setting"
            ],
            [
                "permission" => "permission.roles",
                "title"      => "角色管理",
                "des"        => "添加/删除/查看后台系统的管理员角色.",
                "super"      => false,
                "parent"     => "purview.setting"
            ],
            [
                "permission" => "permission.logs",
                "title"      => "系统日志",
                "des"        => "查看后台系统的所有管理员操作日志.",
                "super"      => false,
                "parent"     => "purview.setting"
            ],
            [
                "permission" => "permission.export",
                "title"      => "数据导出",
                "des"        => "导出用户的所有数据并可以下载.",
                "super"      => false,
                "parent"     => "purview.setting"
            ],
            [
                "permission" => "permission.database",
                "title"      => "数据库备份",
                "des"        => "备份系统的所有数据并且可以下载.",
                "super"      => false,
                "parent"     => "purview.setting"
            ],
        );
    }

    /**
     * 获取全部的区域级权限
     */
    public static function allParent($permissions)
    {
        $parent = array();
        foreach ($permissions as $permission) {
            if (empty($permission['parent'])) {
                $parent[] = $permission;
            }
        }
        return $parent;
    }

    /**
     * 获取区域级权限下级的所有权限
     */
    public static function allChild($parent, $permissions)
    {
        $child = array();
        foreach ($permissions as $permission) {
            if ($permission['parent'] == $parent) {
                $child[] = $permission;
            }
        }
        return $child;
    }

    /**
     *
     */
    public static function canPermission()
    {

    }
}